package com.app.art.config;

import com.app.art.utils.QiNiuOssUtil;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * oss配置类，用来生成AliOssUtil对象，并交由IOC容器管理
 */
@Slf4j
@Configuration
public class OssConfig {

    @Bean
    public QiNiuOssUtil qiniuOssUtil() {
        log.info("初始化qiniuOssUtil对象");
        QiNiuOssUtil aliOssUtil = new QiNiuOssUtil("nIkBBCIqsmAAkt3r1xB2DdZKmoI2HnfDyFBXxobB",
                "kJAuprKvdDnc_MdwuRserebeeqQDRIYrvL9keV04", "wyz5204sky");
        return aliOssUtil;
    }

    @Value("${minio.endpoint}")
    private String endpoint;

    @Value("${minio.access-key}")
    private String accessKey;

    @Value("${minio.secret-key}")
    private String secretKey;

    @Bean
    public MinioClient minioClient() {
        log.info("minioClient {} {} {} ", endpoint, accessKey, secretKey);
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
}
